

import pandas as pd

def process_data(data_dir = "./data_item.csv"):
    ''' 以时间为序，对数据进行重组， 返回数据和数据标签'''
    # data_dir = "./data_item.csv"
    data = pd.read_csv(data_dir)
    dates = pd.to_datetime(data['time'])
    data.set_index(dates)
    new_data = pd.DataFrame(data,
                            columns=['user_id', 'item_id', 'behavior_type', 'item_category'])
    new_data = new_data.set_index(dates, drop=True)

    new_data = new_data.sort_index()
    new_data = new_data.applymap(str) # convert Dataframe to str
    new_data_label = pd.DataFrame(new_data, columns=['item_id'], index=None)
    # onehot
    new_data = pd.get_dummies(new_data)
    new_data_label = pd.get_dummies(new_data_label)
    '''
        new_data: 43
        new_data_label: 24
    '''
    return new_data, new_data_label

process_data()